﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace TextDungeon
{
    /// <summary>
    /// To render something, you need to have in account 2 things: the screens max buffer height and the length of your text or symbol
    /// </summary>
    class GUI
    {
        public Position startpos = new Position();

        public GUI() { }

        public char ByteCode(byte b) 
        {
            return Encoding.GetEncoding(437).GetChars(new byte[] { b })[0];
        }
        /// <summary>
        /// Write A char at assinged position
        /// </summary>
        /// <param name="c">object char</param>
        /// <param name="pos">where on the screen</param>
        /// <param name="color">if you would like a color for the char</param>
        public void WriteAt(char c, Position pos, ConsoleColor color = ConsoleColor.White)
        {
            Console.ForegroundColor = color;
            {

                try
                {
                    Console.SetCursorPosition(pos.X + startpos.X, pos.Y+startpos.Y);
                    Console.Write(c);
                    Console.SetCursorPosition(pos.X+startpos.X, pos.Y+startpos.Y);

                }
                catch (ArgumentOutOfRangeException e)//if a object is renderd outside of bounds the program wont crash on it self
                {
                    pos = new Position();
                    Console.SetCursorPosition(10, 10);
                    Console.WriteLine(e);
                    System.Threading.Thread.Sleep(1000);
                    Console.Clear();
                    //throw;
                } 
                
            }
            Console.ResetColor();
        }

        public void WriteAt(string text, Position pos, ConsoleColor color = ConsoleColor.White) //overloading so that you can write text as well as characters
        {
            Console.ForegroundColor = color;
            {

                try
                {
                    Console.SetCursorPosition(pos.X + startpos.X, pos.Y + startpos.X);
                    Console.Write(text);
                    Console.SetCursorPosition(pos.X + startpos.X, pos.Y + startpos.X);

                }
                catch (ArgumentOutOfRangeException e) 
                {
                    pos = new Position();
                    Console.SetCursorPosition(10, 10);
                    Console.WriteLine(e);
                    System.Threading.Thread.Sleep(1000);
                    Console.Clear();
                    //throw;
                }

            }
        }
    }
}
